<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>00_引入</title>
</head>

<body>
    <button>测试1</button><button>测试2</button><button>测试3</button>
    <script type="text/javascript">
        var btns = document.getElementsByTagName('button')
        // for (var i = 0, length = btns.length; i < length; i++) {
        //     var btn = btns[i]
        //     btn.onclick = function () {
        //         alert('第' + (i + 1) + '个')
        //     }
        // }
        // console.log(i);
        for (var i = 0, length = btns.length; i < length; i++) {
            (function (i) {
                var btn = btns[i]
                btn.onclick = function () {
                    alert('第' + (i + 1) + '个')
                }
            })(i)
        }
        console.log(i);

    </script>
</body>

</html>